package com.meichis.yndms.repository.manager;

import android.util.ArrayMap;

import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.meichis.mcsappframework.utils.MessageTools;
import com.meichis.yndms.http.CallSubscriber;
import com.meichis.yndms.http.IWebServiceCallback;
import com.meichis.yndms.http.RetrofitUtil.RxSchedulersHelper;
import com.meichis.yndms.model.VisitWork;
import com.meichis.yndms.repository.ApiUtil;

/**
 * @author xmy
 * @title
 * @remake
 * @create 2022-03-21 14:58
 */
public class VisitWorkItemJdManager extends BaseManager {

    private static VisitWorkItemJdManager INSTANCE;

    public static VisitWorkItemJdManager getInstance() {
        if (INSTANCE == null) {
            synchronized (VisitWorkItemJdManager.class) {
                if (INSTANCE == null) {
                    INSTANCE = new VisitWorkItemJdManager();
                }
            }
        }
        return INSTANCE;
    }



    public void VisitWorkAdd(final MutableLiveData<Boolean> showDialog, VisitWork Work, MutableLiveData<Integer> data) {
        showDialog.setValue(true);
        ArrayMap<String, Object> hs = new ArrayMap<>();
        hs.put("Work", new Gson().toJson(Work));
        getRootApi().RequestSFA(getToken(), ApiUtil.getRequestPack(hs,"PBMService.VisitWorkAdd"))
                .compose(RxSchedulersHelper.rxSchedulerHelper())
                .subscribe(new CallSubscriber(new TypeToken<String>() {
                }.getType(), new IWebServiceCallback<String>() {
                    @Override
                    public void onSucceed(int sequence,String resultPack, String ReturnInfo, int Return) {
                        data.setValue(Return);
                        showDialog.setValue(false);
                    }

                    @Override
                    public void onFailure(int sequence,int errorCode, String error) {
                        showDialog.setValue(false);
                        MessageTools.showLongToast(error);
                    }
                }));

    }

}
